//
//  PeopleCollectionViewCell.m
//  TQY
//
//  Created by 甘世清 on 2024/10/16.
//

#import "PeopleCollectionViewCell.h"

@implementation PeopleCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.masksToBounds = YES;
        [self SQ_UIViewForSelfView];
    }
    return self;
}
/// 添加ui
-(void)SQ_UIViewForSelfView
{
    [self.contentView addSubview:self.headerView];
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
  
    UIImageView * bgImage = [[UIImageView alloc]init];
    bgImage.image = SQGetImage(@"二级背景");
    bgImage.alpha = 0.2;
    bgImage.contentMode = UIViewContentModeScaleAspectFill;
    bgImage.clipsToBounds = YES;
    [self.headerView addSubview:bgImage];
    [bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.equalTo(self.headerView);
            make.height.mas_equalTo(60);
    }];
    
    UIView * bgView = [[UIView alloc]init];
    bgView.backgroundColor = SQHexColor(@"#000000", 0.4);
    bgView.layer.cornerRadius = 12;
    bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:bgView];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(14);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
        make.height.mas_equalTo(14);
    }];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.nameLabel).insets(UIEdgeInsetsMake(-5, -5, -5, -5));
    }];
    [self.contentView addSubview:self.genderImage];
    [self.genderImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(16);
        make.left.equalTo(bgView).offset(5);
        make.bottom.equalTo(bgView.mas_top).offset(-10);
    }];
    [self.contentView addSubview:self.realStatusImage];
    [self.realStatusImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(16);
            make.left.equalTo(self.genderImage.mas_right).offset(8);
           make.centerY.equalTo(self.genderImage);
    }];
    [self.contentView addSubview:self.vipImage];
    [self.vipImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(16);
        make.left.equalTo(self.realStatusImage.mas_right).offset(8);
        make.centerY.equalTo(self.genderImage);
    }];
    [self.contentView addSubview:self.cityLabel];
    [self.cityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(70);
            make.height.mas_equalTo(26);
            make.top.equalTo(self.contentView).offset(10);
            make.right.equalTo(self.contentView.mas_right).offset(-10);
    }];
    [self.contentView addSubview:self.distanceLabel];
    [self.distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView.mas_right).offset(4);
        make.centerY.equalTo(bgView);
    }];
    
    
}
- (void)setModel:(PeopleModel *)model{
    _model = model;
    [self.headerView sd_setImageWithURL:SQURLImage(model.portrait) placeholderImage:SQGetImage(@"1")];
    self.nameLabel.text = model.name;
    if ([model.gender isEqualToString:@"2"]) {
        self.genderImage.image = SQGetImage(@"女");
    } else {
        self.genderImage.image = SQGetImage(@"男");
    }
    if (model.realStatus == 2) {
        self.realStatusImage.image = SQGetImage(@"renzheng");
    } else {
        self.realStatusImage.image = SQGetImage(@"unrenzheng");
    }
    self.cityLabel.text = self.model.city;
    if (model.isVip) {
        self.vipImage.hidden = NO;
    } else {
        self.vipImage.hidden = YES;
    }
    if (self.model.distance > 0) {
        if (model.distance <1000) {
            self.distanceLabel.text = [NSString stringWithFormat:@"距您:%.fm",model.distance ];
        } else  {
            self.distanceLabel.text = [NSString stringWithFormat:@"距您:%.fkm",model.distance/1000.f];
        }
    } else {
        self.distanceLabel.text = @"";
    }
}
- (UILabel *)cityLabel{
    if (!_cityLabel) {
        _cityLabel = [[UILabel alloc]init];
        _cityLabel.font = FONT_REGULAR(10);
        _cityLabel.textAlignment = NSTextAlignmentCenter;
        _cityLabel.textColor = UIColor.whiteColor;
        _cityLabel.backgroundColor = SQHexColor(@"#000000", 0.4);
        _cityLabel.adjustsFontSizeToFitWidth = YES;
        _cityLabel.layer.cornerRadius = 13;
        _cityLabel.layer.masksToBounds = YES;
    }
    return _cityLabel;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_MEDIUM(13);
        _nameLabel.textColor = UIColor.whiteColor;
        _nameLabel.backgroundColor = UIColor.clearColor;
        _nameLabel.numberOfLines = 0;
    }
    return _nameLabel;
}
- (UILabel *)distanceLabel{
    if (!_distanceLabel) {
        _distanceLabel = [[UILabel alloc]init];
        _distanceLabel.textColor = UIColor.whiteColor;
        _distanceLabel.font = FONT_REGULAR(10);
        _distanceLabel.hidden = YES;
    }
    return _distanceLabel;
}
- (UIImageView *)headerView{
    if (!_headerView) {
        _headerView = [[UIImageView alloc]init];
        _headerView.contentMode = UIViewContentModeScaleAspectFill;
        _headerView.clipsToBounds = YES;
        _headerView.layer.cornerRadius = 10;
        _headerView.layer.masksToBounds = YES;
    }
    return _headerView;
}

- (UIImageView *)genderImage{
    if (!_genderImage) {
        _genderImage = [[UIImageView alloc]init];
        _genderImage.image = SQGetImage(@"女");
    }
    return _genderImage;
}
- (UIImageView *)vipImage{
    if (!_vipImage) {
        _vipImage = [[UIImageView alloc]init];
        _vipImage.image = SQGetImage(@"huiyuanquanyi");
    }
    return _vipImage;
}
- (UIImageView *)realStatusImage{
    if (!_realStatusImage) {
        _realStatusImage = [[UIImageView alloc]init];
        _realStatusImage.image = SQGetImage(@"unrenzheng");
    }
    return _realStatusImage;
}

@end
